<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
  min-width:357px;
  overflow-x:hidden;
}
	
textarea {
	width: 233px;
	height: 18px;
	background-color: #FFFFFF;
}

button {
	width: 235px;
} 	

</style>
<script type="text/javascript" src="jsOAuth-1.3.js"></script>
<script type="text/javascript">
		var year;
		var title;
		var oauth;

		chrome.tabs.getSelected(null, function (tab) {tabToFilmInfo(tab)});

		function tabToFilmInfo(tab) {
			var beginYear; 
			var endYear;
			beginYear = tab.title.indexOf("(");
			endYear = tab.title.indexOf(")");		
				
			title = tab.title.substr(0, beginYear - 1);	
			year = tab.title.substr(beginYear + 1, 4);		
		};

		function showFilmInfo() {
			var text = document.getElementById('text'); 
			text.value = title;		
		};
		
		function linkApp(){
			var op = { consumerKey : 'r3zqy3rer4948d9rnz9kvygs', consumerSecret : '3cEKy8Ph8q'},
				requestParams,
				accessParams;

			var oauth = OAuth(op);

			oauth.get('https://openapi.lovefilm.com/oauth/request_token',
				// success
				function(data) {
					console.info(data);
					var window = openURL('http://example.com/oauth/authorize?'+data.text);
					var requestParams = data.text
					window.onclose = function () {
                var pin = showPinDialog();
					openURL('https://www.lovefilm.com/activate?'+data.text);
					requestParams = data.text;
				},
				// fail!
				function(data) { console.dir(data);	}
			);
			
			
			requestParams
			
				
			// user approved and now we have a pin:
			var oauth_token = 'verify';
			
			oauth.get('http://openapi.lovefilm.com/oauth/access_token' + oauth_token + '&' + requestParams,
				function(data) {
					accessParams = getVarsFromQueryString(data.text);
					oauth.setAccessToken([accessParams.oauth_token, accessParams.oauth_token_secret]);
				},
				// fail!
				function(data) { console.dir(data); }
			);			
		};

		function openURL(url){
			chrome.tabs.create({ 'url' : url});
			var verify = document.getElementById('verify'); 
			verify.value = 'Put code here';	
		};
		
			
		function getFilm(){		
		};
		
	</script>
</head>
<body>
</body>
<body background="hatched_overlay.gif">
	<textarea id="text" cols="" rows=""></textarea>
	<textarea id="verify" cols="" rows=""></textarea>
	<button onclick="showFilmInfo();">ShowInfo</button>
	<button onclick="linkApp();">LinkApp</button>
	<button onclick="verifyApp();">VerifyApp</button>
	<img src="lovefilm-logo-amazon.jpg" alt="LOVEFiLM" />
</body>
</html>


